﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Algorithms;
using Infrastructure;
using Infrastructure.DataTypes;
using System.Collections.ObjectModel;

namespace Controllers
{
    class PredictionAlgorithmController<RatingType> where RatingType : ICountable, new()
    {
        private Dictionary<string, PredictionAlgorithm<RatingType>> predictionAlgList;// List that show what prediction alg are implemented
        public PredictionAlgorithmController()
        {
            SetPredictionAlgrothimsListData();
        }
        /// <summary>
        /// get prediction algorithm list that implemented by user
        /// </summary>
        public ICollection<string> PredictionAlgorithmsList
        {
            get { return predictionAlgList.Keys; }
        }

        /// <summary>
        /// make prediction
        /// </summary>
        /// <param name="user"></param>
        /// <param name="item"></param>
        /// <param name="predictionType"></param>
        /// <returns></returns>
        public double Prediction(User<RatingType> user, Item<RatingType> item, string predictionType)
        {

            double ans = double.NaN;
            if (predictionAlgList.ContainsKey(predictionType))
                return predictionAlgList[predictionType].PredictRating(user, item);
            return ans;
        }



        private void SetPredictionAlgrothimsListData()
        {
            predictionAlgList = new Dictionary<string, PredictionAlgorithm<RatingType>>();
            predictionAlgList["Pearson"] = AlgorithmsFactory<RatingType>.CreatePredictionAlgorithm("Pearson");
            predictionAlgList["Cosine"] = AlgorithmsFactory<RatingType>.CreatePredictionAlgorithm("Cosine");
            predictionAlgList["Random"] = AlgorithmsFactory<RatingType>.CreatePredictionAlgorithm("Random");
            predictionAlgList["Stereotypes"] = AlgorithmsFactory<RatingType>.CreatePredictionAlgorithm("Stereotypes");
        }

    }
}
